import { defineStore } from 'pinia'
import { getUserInfo, getMenuList, getPermissionList } from '@/api'
import { resetRouter } from '@/router'
import store from '../index'

const getMeunList = (data) => [
  data.map((v) => {
    return {}
  })
]

export const userApp = defineStore('app', {
  state: () => ({
    spinning: false,
    keepAliveRoutes: new Set(),
    userInfo: '',
    menuList: [],
    permissionList: []
  }),
  getters: {},
  actions: {
    Loading(payload: boolean) {
      this.spinning = payload
    },
    keepAliveRoutesPush(payload) {
      this.keepAliveRoutes.add(payload)
    },
    keepAliveRoutesDel(payload) {
      this.keepAliveRoutes.delete(payload)
    },
    keepAliveRoutesClear() {
      this.keepAliveRoutes.clear()
    },
    setUserInfo(payload: g.object) {
      this.userInfo = payload
    },
    async GetUserInfo() {
      const res = await getUserInfo(store.userStore.orgId)
      this.setUserInfo(res.data)
      // this.setUserInfo({
      //   name: 'admin'
      // })
    },
    async GetMenuList() {
      // const res = await getMenuList(store.userStore.platformId)

      const data = [
      //   {
      //     path: '/doctorManagement',
      //     name: 'doctorManagement',
      //     meta: { title: '医生管理', icon: 'FileSearchOutlined' },
      //     component: () => import('@/views/doctorManagement/index.vue')
      //   },
      //   {
      //     path: '/commodityManagement',
      //     name: 'commodityManagement',
      //     meta: { title: '商品管理', icon: 'FileSearchOutlined' },
      //     component: () => import('@/views/commodityManagement/index.vue')
      //   },
      //   {
      //     path: '/patientManagement',
      //     name: 'patientManagement',
      //     meta: { title: '患者管理', icon: 'SolutionOutlined' },
      //     component: () => import('@/views/patientManagement/index.vue')
      //   },
      //   {
      //     path: '/healthManagement',
      //     name: 'healthManagement',
      //     meta: { title: '健管师管理', icon: 'SolutionOutlined' },
      //     component: () => import('@/views/healthManagement/index.vue')
      //   },
        {
          path: '/templateManage',
          name: 'templateManage',
          meta: { title: '模板管理', icon: 'SettingOutlined' },
          component: () => import('@/views/templateManage/index.vue')
        }
      ]
      this.menuList = resetRouter(data)
    },
    async GetPermissionList() {
      const res = await getPermissionList()
      this.permissionList = res.data
    }
  }
})
